package com.chaoyi.service.Impl;

import com.chaoyi.config.WSUploadConfig;
import com.chaoyi.service.EditorFileService;
import com.chaoyi.util.UUIDUtil;
import com.chaoyi.util.qiniu.UploadFileQiNiu;
import org.joda.time.DateTime;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.Part;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

/**
 * @author xuanqicheng
 * @create 2018-11-下午3:02
 */
@Service
public class EditorFileServiceImpl implements EditorFileService {
    @Override
    public Map<String, Object> uploadImages(Part upfile) throws Exception {

        String exten = upfile.getSubmittedFileName().substring(upfile.getSubmittedFileName().lastIndexOf("."));

        String fileName = UUIDUtil.getUUID() + exten;

        String savePath = UploadFileQiNiu.uploadFile(upfile, WSUploadConfig.koreanVideoUrlPath, fileName);


        //上传成功返回true，否则返回false

        Map<String,Object> map = new HashMap<String,Object>();
        if(true){
            map.clear();
            map.put("state","SUCCESS");
            map.put("original",upfile.getSubmittedFileName());
            map.put("size",upfile.getSize());
            map.put("title",fileName);
            map.put("type",exten);
            map.put("url",savePath);
        }
        return map;
    }
}
